﻿using InsuranceCompany.Core.Domain.InsuranceObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InsuranceCompany.Core.Domain.InsuranceObjects
{
    public class Accident : Document
    {
        public string Description { get; set; }
        public string Assessment { get; set; }
        public Policy Policy { get; set; }
        public Decimal LossSum { get; set; }
        private String result;
        public String Result 
        {
            get
            {
                return result;
            }
            set
            {
                this.resetErrorMessage();
                if ((value != "Рассмотрение") && (value != "Отклонено") && (value != "Принято"))
                {
                    this.setErrorMessage("Impossible accident result value!");
                    return;
                }
                result = value;
            }
        }
        public DateTime AccidentDate { get; set; }

        private Decimal PaymentSum = 0;

        public Accident() :base()
        {
            Description = "";
            Assessment = "";
            Policy = null;
            LossSum = 0.0M;
            Result = "Рассмотрение";
            AccidentDate = DateTime.Today;
        }

        public Accident(Accident a)
            : base(a)
        {
            Description = a.Description;
            Assessment = a.Assessment;
            Policy = new Policy(a.Policy);
            LossSum = a.LossSum;
            Result = a.Result;
            AccidentDate = a.AccidentDate;
            PaymentSum = a.GetPaymentSum();
        }

        public Accident(string description, string assessment, ref Policy policy, Decimal lossSum, string result, DateTime accidentDate)
            : base()
        {
            Description = description;
            Assessment = assessment;
            Policy = new Policy(policy);
            LossSum = lossSum;
            Result = "Рассмотрение";
            AccidentDate = accidentDate;
            CalculatePaymentSum();
        }

        public Decimal GetPaymentSum() { return PaymentSum; }
        public Decimal CalculatePaymentSum() 
        {
            PaymentSum = 0;
            if (Result != "Принято")
            {
                PaymentSum = 0;
                return PaymentSum;
            }
            if (LossSum > Policy.GetRestSum())
                PaymentSum = Policy.GetRestSum();
            else
                PaymentSum = LossSum;
            return PaymentSum;
        }

    }
}
